﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
using ModuleDALCore;
using System.Data;
namespace DAL
{
    public class LoaiNhanVienDAO : DALBase
    {
        public LoaiNhanVienDAO()
        {
            this.OpenConnect();
        }
        private String _spName;

        public String SpName
        {
            get { return "SpLoaiNhanVien"; }
            set { _spName = value; }
        }
        public DataTable SELECTBYPK(int id)
        {
            try
            {
                LoaiNhanVienDTO dv = new LoaiNhanVienDTO();
                dv.IDLoaiNhanVien = id;
                return DBManager.Intance.ExecuteDataTable(SpName, ConvertClassToArray.GetParamName(dv, null), ConvertClassToArray.GetValues(dv, 4));
            }
            catch (Exception ex)
            {
                throw new InvalidProgramException(ex.Message);
            }
        }
        public bool INSERT(LoaiNhanVienDTO dv)
        {
            try
            {
                return (DBManager.Intance.ExecuteNonQuery(SpName, ConvertClassToArray.GetParamName(dv, null), ConvertClassToArray.GetValues(dv, 1)) == 1);
            }
            catch (Exception ex)
            {
                throw new InvalidProgramException(ex.Message);
            }
        }
        public bool UPDATE(LoaiNhanVienDTO dv)
        {
            try
            {
                return (DBManager.Intance.ExecuteNonQuery(SpName, ConvertClassToArray.GetParamName(dv, null), ConvertClassToArray.GetValues(dv, 2)) == 1);
            }
            catch (Exception ex)
            {
                throw new InvalidProgramException(ex.Message);
            }
        }
        public bool DELETE(LoaiNhanVienDTO dv)
        {

            try
            {
                return (DBManager.Intance.ExecuteNonQuery(SpName, ConvertClassToArray.GetParamName(dv, null), ConvertClassToArray.GetValues(dv, 3)) == 1);
            }
            catch (Exception ex)
            {
                throw new InvalidProgramException(ex.Message);
            }
        }
        public DataTable SELECTALL()
        {
            try
            {
                LoaiNhanVienDTO dv = new LoaiNhanVienDTO();
                return DBManager.Intance.ExecuteDataTable(SpName, ConvertClassToArray.GetParamName(dv, null), ConvertClassToArray.GetValues(dv, 0));
            }
            catch (Exception ex)
            {
                throw new InvalidProgramException(ex.Message);
            }
        }
    }
}
